package com.cychat.mall.controller;

import com.Cychat.commons.entity.ResultMessage;
import com.Cychat.commons.entity.pojo.ProductCategory;
import com.cychat.mall.service.ProductCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Auther: 刘俊  <br/>
 * Date: 2025-10-30:下午 7:03  <br/>
 * Description: 商品分类控制器
 */
@RestController
@RequestMapping("/api/mall")
@CrossOrigin
public class ProductCategoryController {
    @Autowired
    private ProductCategoryService productCategoryService;
    @GetMapping("/productCategory/list")
    public ResultMessage<List<String>> list() {

        List<ProductCategory> productCategories = productCategoryService.list();
        // 2. 提取所有name属性到新数组
        List<String> categoryNames = productCategories.stream()
                .map(ProductCategory::getName) // 提取name属性
                .collect(Collectors.toList()); // 收集为List<String>
        return ResultMessage.success(categoryNames);
    }
}
